package top.huhuiyu.springboot.study.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 胡辉煜
 */
// @Aspect表示该类为切面处理类
@Aspect
@Component
@Slf4j
@Order(100)
public class ControllerLogger implements BaseControllerAop {

  @Before("pointcut()")
  public void before(JoinPoint jp) {
    log.debug("控制器切面前置========================================");
    log.debug("前置信息：{}", jp.getSignature());
    Object[] args = jp.getArgs();
    if (args == null || args.length == 0) {
      log.debug("方法没有参数");
      return;
    }
    log.debug("方法的参数信息：");
    for (Object arg : args) {
      log.debug("参数：{}", arg);
    }
  }


  @After("pointcut()")
  public void after(JoinPoint jp) {
    log.debug("{}切面后置========================================", jp.getSignature().toShortString());
  }

  @AfterReturning(pointcut = "pointcut()", returning = "result")
  public void afterReturning(JoinPoint jp, Object result) {
    log.debug("{}的返回值：{}", jp.getSignature().toShortString(), result);
  }


}
